﻿<?php
class Article {

    public $id;
    public $userID;
    public $subject;
    public $tags = array();
    public $text;
    public $time;
    
    public function __construct($data = null) {
        
        if(is_array($data)) {
            @$this->id = $data['id'];
            @$this->userID = $data['userID'];
            $this->subject = $data['subject'];
            
            if(is_string($data['tags'])){ 
                $tagArray = explode(',',$data['tags']);
                $this->tags = array_map('trim', $tagArray);
            }
            else $this->tags = $data['tags'];
            
            $this->text = $data['text'];
            @$this->time = $data['time'];
        }
    }
    
    public function isOwner($id) {
        if($this->userID == $id) return true;
        else return false;
    }
    
    public function getStringTags() {
            $tags = implode(', ', $this->tags);
            return $tags;
    }
}

?>